public class code6 {
    //查找总价格为目标值的两个商品
    //解法一：双指针：看指针指向的两个值与目标值的关系进行指针的移动
    public int[] twoSum(int[] price, int target) {
        int[] arr = new int[2];
        int slow=0,fast=price.length-1;
        while(slow<fast) {
            if(price[slow]+price[fast]<target) slow++;
            else if(price[slow]+price[fast]>target) fast--;
            else {
                arr[0] = price[slow];
                arr[1] = price[fast];
                break;
            }
        }
        return arr;
    }
}
